﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using Microsoft.Owin.Security.OAuth;
using Newtonsoft.Json.Serialization;

namespace Api
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API 配置和服务
            // 将 Web API 配置为仅使用不记名令牌身份验证。
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API 路由
            config.MapHttpAttributeRoutes();
            //config.MapHttpAttributeRoutes(new CustomDirectRouteProvider());

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            config.Routes.MapHttpRoute(
                name: "DefaultAdpi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        } 
    }

    //public class CustomDirectRouteProvider : DefaultDirectRouteProvider
    //{
    //    protected override IReadOnlyList<IDirectRouteFactory>
    //    GetActionRouteFactories(HttpActionDescriptor actionDescriptor)
    //    {
    //        return actionDescriptor.GetCustomAttributes<IDirectRouteFactory>
    //        (inherit: true);
    //    }
    //}
}
